package com.mz.ozy.widget.dialog;

import android.app.Activity;
import android.content.Context;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.widget.EditText;

import com.mz.ozy.R;
import com.mz.ozy.utils.ToastUtils;


/**
 * Created by administrator on 2019/3/14.
 */
public class NameEditDialog extends BaseDialog implements View.OnClickListener{

    private EditText nameEt;

    public NameEditDialog(Activity mContext) {
        super(mContext, R.layout.dialog_name_edit, Gravity.CENTER, true);
        init();
    }

    private void init(){
        nameEt = getView(R.id.nameEt);
        getView(R.id.confirmTv).setOnClickListener(this);
        getView(R.id.cancelTv).setOnClickListener(this);
        getView(R.id.image).setOnClickListener(this);

    }


    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.image:
                nameEt.setText("");
                break;
            case R.id.cancelTv:
                toggleDialog();
                break;
            case R.id.confirmTv:
                String name = nameEt.getText().toString().trim();
                if(TextUtils.isEmpty(name)){
                    ToastUtils.showToast(mContext.getString(R.string.nickname_not_allow_empty));
                    return;
                }
                if(mListener!=null){
                    mListener.onConfirm(name);
                }
                toggleDialog();
                break;
        }
    }

    private onDialogListener mListener;
    public void setOnDialogListener(onDialogListener listener){
        mListener = listener;
    }
    public interface onDialogListener{
        void onConfirm(String name);
    }
}
